package com.lookpoint.controller;

import com.lookpoint.exception.ServiceException;
import com.lookpoint.util.Result;
import com.lookpoint.util.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<?> handleException(Exception e) {
        Result<?> result;
        if (e instanceof ServiceException) {
            result = Result.error(ResultCode.SERVER_ERROR);
        } else {
            result = Result.error(ResultCode.SERVER_ERROR);
        }
        return result;
    }
}
